<?php
include_once("/var/www/html/new/com.inc.php");
include_once('/var/www/html/new/d/module/api/glyld/glyld.class.php');

exit;
$gly_client = new Ferry_gly(); 
$feline_xml = $gly_client->getFlightLine(); // 获取航线信息
$feline_sim = simplexml_load_string($feline_xml);


$request = array();
foreach($feline_sim->content->list->flightLine as $flight){
	// print_r($flight);
	foreach($flight->ticketList->ticket as $ticket){
		$option['lid']   = 10253;
		$option['apply_did']  = 27491;
		$option['uuid']  = (string)$flight->id.'_'.(string)$ticket->id;
		$option['title'] = (string)$flight->name.(string)$ticket->name;
		$option['price'] = (float)$ticket->price;
		$option['tid']   = 0;
		$sql = "select t.id,t.pid,f.id as fid from uu_jq_ticket t left join uu_land_f f on t.id=f.tid where landid={$option['lid']} and uuid='{$option['uuid']}' limit 1";
		$GLOBALS['le']->query($sql);
		if($GLOBALS['le']->fetch_assoc()){
			$option['tid'] = $GLOBALS['le']->f('id');
			$option['pid'] = $GLOBALS['le']->f('pid');
			$option['fid'] = $GLOBALS['le']->f('fid');
		}
		$request[] = simple_params($option);
	}
}

foreach($request as $row){
	print_r(get_url_content('http://10.160.4.140/new/d/a/z.php', $row));
}
// print_r($request[0]);//查询航线信息
// print_r(get_url_content('http://10.160.4.140/new/d/a/z.php', $request[0]));




function simple_params(Array $option){
	
	$params = array();
	if(isset($option['pid'])) $params['pid'] = $option['pid'];
	$params['tTitle'] = $option['title'];
	$params['uuid']   = $option['uuid'];
	$params['price1'] = $option['price']+20;
	$params['lastid'] = $option['lid'];// 景区ID
	$params['did']    = $option['apply_did'];// 供应商ID
	$params['ptype']  = 'A';
	$params['tid']    = $option['tid'];
	if(!isset($option['fid'])){
		$params['ticket'] = array(
			array(
				'bt'=> date('Y-m-d'),
				'et'=> date('Y-12-31'),
				'normalDay'=> array(0,1,2,3,4,5,6),
				'pg'=> $option['price'],
				'pl'=> $option['price']+10,
				'price1'=> $option['price']+20,
				'storage'=>'不限'
			)
		);	
	}
	$params['f'] = array('dhour'=>23, 'dmin'=>59, 'v_ID_support'=>0, 'tourist_info'=>0, 'confirm_sms'=>0, 'v_time_limit'=>0);
	if(isset($option['fid'])) $params['f']['fid'] = $option['fid'];
	
	$params['action'] = 'CreateNewTicket';
	
	$params['payType'] = 1;
	$params['cancel_time'] = 120;// 支付有效时间
	$params['verify_limit'] = array(1,2,3,4,5,6,7);// 验证时间
	$params['order_start'] = '';// 验证时间
	$params['order_end']   = '';// 验证时间
	$params['blimit_low']  = 1;// 验证时间
	$params['blimit_up']   = 0;
	$params['earyTime']    = 0;
	$params['TicketExplain'] = '';
	$params['TicketInfo'] = '取票信息:';
	$params['sendVoucher'] = 0;
	$params['confirm_wx'] = 0;
	$params['earyTime'] = 0;
	$params['validTime'] = 0;
	$params['vt'] = 0;
	$params['ticketMedia'] = 0;
	$params['saleTime'] = 1;
	$params['provide_to'] = 0;
	$params['reb'] = '';
	$params['reb_type'] = 0;
	
	$params['ttype'] = 1;	
	$params['mdetails'] = 1;
	$params['mpath'] = 'http://10.160.4.140/new/d/module/api/glyld/gly_get_data.php';// 模块处理路径
	
	return $params;
}

function get_url_content($url,$data){    
    $user_agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)";     
    $ch = curl_init();    
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data));  
    curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
    curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
    curl_setopt ($ch, CURLOPT_AUTOREFERER, 1);
    curl_setopt ($ch, CURLOPT_HEADER,0);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);    
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);    
    curl_setopt ($ch, CURLOPT_TIMEOUT, 10);
    $result = curl_exec($ch);    
    curl_close($ch);    
    return $result;    
}

